package com.yakaten.utils;

import java.io.File;
import java.util.Date;
import java.util.TimerTask;

import org.apache.log4j.Logger;
import org.seasar.framework.util.ResourceUtil;


public class DeleteFileTask extends TimerTask {

	static Logger logger = Logger.getLogger(DeleteFileTask.class);

	@Override
	public void run() {
		if(logger.isInfoEnabled()){
			logger.info("------------------delete file start----------------------");
		}
		Date date = new Date();
		long currentTime = date.getTime();
		long kenkaku = 1000*60*60;


		File kakakuTmpFileFolder = new File(ResourceUtil
				.getProperties("yakaten.properties").getProperty(
				"kakaku.csv.folder"));
		File[] kakakuTmpFileList = kakakuTmpFileFolder.listFiles();

		for(File current:kakakuTmpFileList){
			if(currentTime-current.lastModified()>kenkaku){
				current.delete();
			}
		}


		File amazonTmpFileFolder = new File(ResourceUtil
				.getProperties("yakaten.properties").getProperty(
				"amazon.mws.updateprice.feedfilepath"));
		File[] amazonTmpFileList = amazonTmpFileFolder.listFiles();

		for(File current:amazonTmpFileList){
			if(currentTime-current.lastModified()>kenkaku){
				current.delete();
			}
		}

		if(logger.isInfoEnabled()){
			logger.info("------------------delete file end----------------------");
		}
	}

}
